<style xmlns="http://www.w3.org/1999/html">
    .layui-input, .layui-textarea {
        display: block;
        width: 90%;
        padding-left: 10px;
    }

    .layui-form-label.required:before { /* 这种写法也可以*/
        content: ' *';
        color: red;
    }


    .layui-form-label {
        float: left;
        display: block;
        padding: 9px 15px;
        width: 104px;
        font-weight: 400;
        line-height: 20px;
        text-align: right;
    }

    .import {
        opacity: 0;
        position: absolute;
        width: 69px;
        height: 38px;
        margin-left: -10px;
    }

    .layui-form-item {
        margin-right: 18px;
    }
</style>

<form lay-filter="batchInsertForm" class="layui-form productForm form-scroll model-form">
    <div class="examineProductionPlanForm-title">
        <h3 class="title">提货订单信息</h3>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label required">提货订单编号：</label>
            <div class="layui-input-block">
                <select id="orderNoInfo" lay-search="" name="orderNoInfo" lay-filter="orderNoInfo"
                        class="common-select-search">
                </select>
            </div>
        </div>
        <div class="layui-col-md4 required">
            <label class="layui-form-label">订单类型：</label>
            <div class="layui-input-block">
                <select id="orderType" disabled name="orderType" class="common-select-search"
                        lay-verify="required">
                </select>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label required">所属客户：</label>
            <div class="layui-input-block">
                <select id="customerInfo" disabled name="customerInfo" lay-filter="customerInfo"
                        class="common-select-search">
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label required">采购客户代码：</label>
            <div class="layui-input-block">
                <input id="purchaseCode" disabled name="purchaseCode" placeholder="采购客户代码" type="text"
                       class="layui-input"
                       lay-verify="required"
                       required autocomplete="off"/>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label required">订单下单时间：</label>
            <div class="layui-input-block">
                <input id="orderTime" disabled name="orderTime" placeholder="订单下单时间" type="text"
                       class="layui-input"
                       required autocomplete="off"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label required">提货时间：</label>
            <div class="layui-input-block">
                <input type="text" id="deliveryTime" placeholder="选择提货时间" name="deliveryTime" class="layui-input">
            </div>
        </div>
    </div>
    <div class="examineProductionPlanForm-title">
        <h3 class="title">导入文件</h3>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label required">上传导入文件：</label>
            <button id="uploaderInputButAAA" class="layui-btn icon-btn color-reseda">
                <input id="uploaderInputAAA" type="file" name="file" class="import" accept=".xls,.xlsx"/>导入
            </button>
        </div>
    </div>
    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var config = layui.config;
        var admin = layui.admin;
        var form = layui.form;
        var laydate = layui.laydate;


        laydate.render({
            elem: '#deliveryTime'
            , type: 'date'
        });

        let selectMap = new Map();
        //提货订单 初始化
        admin.initDataSelectAndMap("production/delivery/admin/orderInfo/list", {limit: 9999}, "orderNoInfo", null, "提货订单", "orderNo", "id", selectMap);

        form.on('select(orderNoInfo)', function (data) {
            let val = data.value;
            if (val) {
                let orderInfo = selectMap.get(val);
                $("#orderTime").val(orderInfo.orderTime)
                $("#purchaseNameInfo").val(orderInfo.purchaseName)
                $("#purchaseCode").val(orderInfo.purchaseCode)
                $("#orderType").val(orderInfo.orderType)
                $("#orderNo").val(orderInfo.orderNo)
                //订单类型
                admin.getDictList("orderType", "pro_product_order_type", orderInfo.orderType, "订单类型");

                admin.req('enterprise/sell/admin/customersInfo/list', {limit: 9999}, function (res) {
                    if (res.code == 200) {
                        if (res.data.length > 0) {
                            $.each(res.data, function (index, item) {
                                $('#customerInfo').append(new Option(item.customerName, item.id));
                            })

                            $("#customerInfo").val(orderInfo.customerId)
                            form.render('select');
                        }
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'GET');
            } else {
                $("#orderTime").val()
                $("#purchaseNameInfo").val()
                $("#purchaseCode").val()
                $("#orderType").val()
                $("#orderNo").val()
                $("#customerInfo").val()
                form.render('select');
            }
        });

        // 导入excel
        $('#uploaderInputAAA').on("change", function (e) {
            let orderNo = $("#orderNoInfo").val();
            let deliveryTime = $("#deliveryTime").val();
            var formData = new FormData();
            let files = e.target.files;
            formData.append("file", files[0]);
            formData.append("name", files[0].name);//这个地方可以传递多个参数
            formData.append("orderNo", orderNo);//这个地方可以传递多个参数
            formData.append("deliveryTime", deliveryTime);//这个地方可以传递多个参数
            if (!orderNo && !deliveryTime) {
                layer.msg('订单编号和提货时间不能为空!', {icon: 2});
                return false;
            } else {
                layer.load(2);
                $.ajax({
                    url: config.base + 'production/delivery/admin/orderDetailInfo/importExcel',
                    data: formData,
                    headers: {Authorization: 'Bearer ' + config.getToken()},
                    type: "POST",
                    processData: false,
                    contentType: false,
                    success: function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            layer.msg(res.msg, {icon: 1});
                            layer.closeAll('page');
                            setTimeout(_ => {
                                location.reload()
                            }, 1000);
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }
                });
            }
        });


    });
</script>